<?php
	/**
	 * 连续登录奖励
	 */

	class LoginRewardInfo extends APIBase {
			
		public $tag = "LoginRewardInfo";
        public $isvip = true;
		
		public function before() {
			$this->initMysql();
			return true;
		}

		public function logic() {
			$login_info = $this->data_redis->hmGet("hu:{$this->uid}", array('login_days', 'is_get'));
			
			/*var_dump($login_info);
			exit;*/
			$is_get = (int)$login_info['is_get'];
			if ($is_get == 0) {
				$login_info['login_days'] = (int) $login_info['login_days'];
				//if ($login_info['login_days'] > 0) {
					$index = (int)$login_info['login_days'] + 1;
					if($login_info['login_days'] >= 7){
						$index = 7;
						$this->data_redis->hset("hu:{$this->uid}","login_days",0);
					}
					//$this->mysql->select("",);
					//$money = $this->data_redis->hincrBy("hu:{$this->uid}", "money", Game::$login_reward_money[$index]);
					$re = $this->mysql->find("select * from loginreward where days=".$index."");
					foreach($re as $lre){
					   	if($lre['propid'] && $lre['prop_num']){
							 for($i=0;$i<(int)$lre['prop_num'];$i++){
								//赠送道具 
								$playprop = array('uid'=>$this->uid,'propid'=>$lre['propid'],'createtime'=>time());
	                         	$result = $this->mysql->insert("player_prop", $playprop); 
							  } 
						}
						//赠送金币
						if($lre['give_money']){
						  $money=$this->data_redis->hincrBy("hu:{$this->uid}", "money", $lre['give_money']);
						  
						  Config::$logger->info($this->tag, " IP:".$this->getRealIp()." ".$this->uid.'更加后金额：'.$money.'增加量：'.$lre['give_money']);
						  //领取金币记录
						  $m_rec['type'] = 3;
						  /*$m_rec['vid'] = 0;
						  $m_rec['tid']  = 0;
						  $m_rec['seatid']  = 0;*/
						  $m_rec['uid']  =  $this->uid;
						  $m_rec['money'] = $money;
						  $m_rec['change_money']  =  $lre['give_money'];
						  $this->addChangeMongeyLog($m_rec);
						  
						  
						}
						//赠送元宝
						if($lre['give_coin']){

					      $coin = $this->data_redis->hincrBy("hu:{$this->uid}", "coin", $lre['give_coin']);
						  Config::$logger->info($this->tag, " IP:".$this->getRealIp()." ".$this->uid.'更加后：'.$coin.'增加量：'.$lre['give_coin']);

						}
						//赠送奖券
						//$this->data_redis->hincrBy("hu:{$this->uid}", "money", Game::$login_reward_money[$index]);
						
					}
					
					
					$this->data_redis->hincrBy("hu:{$this->uid}", "login_days", 1);
					$this->data_redis->hSet("hu:{$this->uid}", "is_get", 1);
					/*$day_reward = array();
					for ($i = 0; $i< sizeof(Game::$login_reward_money); $i++){
						$reward = array();
						$reward['money'] = Game::$login_reward_money[$i];
						$day_reward[] = $reward;
					}*/
					$login_days = $this->data_redis->hGet("hu:{$this->uid}",'login_days');
					//$this->returnData(array('money'=> $money, 'login_days'=> $login_info['login_days'], 'day_reward_arr' => Game::$login_reward_money));
					$this->returnData(array('login_days'=> (int)$login_days));
				//}
			}else{
				//$this->returnError(321, 'u have getted reward');
			}
		}

		public function after() {
			$this->deinitMysql();
			$this->deinitDataRedis();
		}
	}
?>
